module.exports = function($scope, $state, $stateParams, $modalInstance,addcard,poolcode,unusedcard,getcardtasklist){
    console.log(poolcode);
    console.log(getcardtasklist);
    /* 分页
     * ========================================= */
    $scope.maxSize = 5;            //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 5;         //每页显示几条
    $scope.getunusedcard = function(){ 
    	var para = {
            pageNo:$scope.bigCurrentPage, 
            pageSize:$scope.itemsPerPage,
            type : '0',
            pool_code : poolcode
        };
        //para = angular.extend($scope.searchform, para);
        getcardtasklist.save(para, function(res){ 
        	console.log(para);
    	    if (res.errcode !== 0) { 
    		    alert(res.errmsg);
    	    } else { 
    		    $scope.cardinfos = res.data.results;
    		    $scope.bigTotalItems = res.data.totalRecord;
    		    console.log(res);
    	    }
        });
    };
    $scope.getunusedcard();

    $scope.cardinfo = {
    	'type' : '1',
    	'start_card_num' : '',
      'end_card_num' : '',
      'pool_code' : poolcode
    };

    $scope.ok = function () {
    //     var array = [];
		// // 声明一个要传的参数变量
		// var cardparem = {'type':$scope.cardinfo.type};
		// // 根据type类型不同参数的属性是不同的
    //     if ($scope.cardinfo.type === '2') {
    //     	cardparem['cardnum'] = $scope.cardinfo.cardnum;
    //     	array.push(cardparem);
        	
    //     } else if ($scope.cardinfo.type === '1'){
    //     	cardparem['startnum'] = $scope.cardinfo.startnum;
    //     	cardparem['endnum'] = $scope.cardinfo.endnum;
    //     	array.push(cardparem);
    //     } 
        
    // 	for (var i = 0; i < $scope.cardinfos.length; i++) {
    // 	    var tmp = $scope.cardinfos[i];
    //         if (tmp.value == 1) { 
    //             var arrayObj = {
    //        	        'type' : '1',
    //       	        'startnum' : tmp.mincard,
    //       	        'endnum' : tmp.maxcard
    //             };
    //             array.push(arrayObj);	
    //         }
    //     };
        // if (array.length === 0) { 
        // 	alert('卡号不能为空!');
        // 	return;
        // } 
        // var para = {'poolcode' : poolcode};
        // para['list'] = array;
        // console.log(para);
        if ($scope.cardinfo.start_card_num > $scope.cardinfo.end_card_num){
          alert('起始卡号不能大于结束卡号');
        } else {
          addcard.save($scope.cardinfo, function(res){
            if (res.errcode !== 0) {
                alert(res.errmsg);
            } else {
                alert('添加卡成功');
                $scope.getunusedcard();
    
                // $modalInstance.close();
              //$state.go('app.cardpool');
            }
            
          }); 
        }
         
    };

    $scope.cancel = function () {
      $modalInstance.dismiss('cancel');
    };
};